package com.summer.utils.apktool;

import com.alibaba.fastjson.JSONObject;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class YamlUtils {

    public static void main(String[] args) throws FileNotFoundException {

        Yaml yaml = new Yaml();
        YamlSchema yamlSchema = yaml.loadAs(new FileInputStream(new File("/Users/haoyitao/Documents/需求/apk下载/yaml-xml parse/apktool.yml")), YamlSchema.class);
        System.out.println(JSONObject.toJSON(yamlSchema));
        System.out.println(JSONObject.toJSON(yamlSchema.getVersionInfo().get("versionName")));
    }

    public static String getVersionCode(String filePath) throws Exception {
        FileInputStream fileInputStream = null;
        try{
            Yaml yaml = new Yaml();
            fileInputStream = new FileInputStream(new File(filePath));
            YamlSchema yamlSchema = yaml.loadAs(fileInputStream, YamlSchema.class);
            return yamlSchema.getVersionInfo().get("versionName");
        }catch(Exception ex){
            ex.printStackTrace();
            return null;
        }finally {
            if(fileInputStream!=null){
                fileInputStream.close();
            }
        }
    }
}
